"""this script parse the content of a xml file"""
import time
import sys
from PyQt5.QtCore import QThread, QMutex
from ui.ui_operate import UIOperate


class MainLogic(QThread):
    """Summary of class here.
       测试流程
    """
    #QMutex类提供的是线程之间的访问顺序化。
    #QMutex的目的是保护一个对象、数据结构或者代码段，所以同一时间只有一个线程可以访问它
    pause = QMutex()
    """
    self.pause.lock()
    self.pause.lock()
    self.pause.unlock()
    """

    def __init__(self):
        super().__init__()
        self.signal = UIOperate()
        self.zh_level_dict = {
            1: 40,
            2: 70,
            3: 100,
            4: 140,
            5: 210,
            6: 320,
            7: 490,
            8: 740,
            9: 1110,
            10: 1640,
            11: 2380,
            12: 3380,
            13: 4710,
            14: 6430,
            15: 8670,
            16: 12140,
            17: 17870,
            18: 27320,
            19: 42910,
            20: 68630
        }
        #秋装  对应仙点
        self.qiu_dict = {
            1: {"qiu_tou": 30},
            2: {"zqiu_tou": 6 * 30},
            3: {"qiu_mian": 360},
            4: {"zqiu_mian": 8 * 360},
            5: {"qiu_shou": 300},
            6: {"zqiu_shou": 9 * 300},
            7: {"qiu_xiang": 340},
            8: {"zqiu_xiang": 9 * 340},
            9: {"qiu_yi": 140},
            10:{"zqiu_yi": 6 * 140},
            11: {"qiu_bao": 20},
            12: {"zqiu_bao": 8 * 20},
            13: {"qiu_xie": 260},
            14: {"zqiu_xie": 8 * 260},
            15: {"qiu_jie": 100},
            16: {"zqiu_jie": 8 * 100},
        }
        #仙豆价格
        self.xd_price = 0
        #战魂参考价格 以10级战魂为参考
        self.zh_refer = 0
        self.zh_level_10 = 10
        # 计算标志位
        self.start_calc = False

    def __zh_calc(self):
        """
        战魂价格计算
        :param :None
        :return:None
        """
        #计算每点战魂经验的价格
        zh_per_price = self.xd_price * self.zh_refer / self.zh_level_dict[
            self.zh_level_10]
        for i in range(1, 21):
            zh_price = round(zh_per_price * self.zh_level_dict[i], 3)
            # 金币
            zh_j = int(zh_price)
            # 银币
            zh_y = int(1000 * round(zh_price - zh_j, 3))
            self.signal.signal_main_zh_price_show.emit(str(i), str(zh_j), str(zh_y))

    def __xd_calc(self):
        """
        仙点价格计算
        :param :None
        :return:None
        """
        #计算每点仙点的价格 一个仙豆等于74仙点
        xd_per_price = (self.xd_price / 74)
        for i in range(1, 17):
            qiu_price = round(xd_per_price * list(self.qiu_dict[i].values())[0], 3)
            qiu_j = int(qiu_price)
            qiu_y = int(1000 * round(qiu_price - qiu_j, 3))
            self.signal.signal_main_qiu_price_show.emit(list(self.qiu_dict[i].keys())[0], str(qiu_j), str(qiu_y))

    def run(self):
        """
        逻辑线程
        :param :None
        :return:None
        """
        while True:
            time.sleep(0.5)
            if self.start_calc is True:
                self.start_calc = False
                try:
                    self.__zh_calc()
                    self.__xd_calc()
                except:
                    print("计算运行错误")


if __name__ == '__main__':
    pass
